// Copyright (c) 2009 Luca Marrocco.
// Modified or written by Luca Marrocco for inclusion with codej.
// Licensed under the Apache License, Version 2.0 (the "License")
package codej.gen;

import codej.ast.*;
import codej.gen.java.*;

/** @author Luca Marrocco */
public class Generators {

	private interface DelegateGenerator {
		String generate();
	}

	public static String clean(String generated) {
		return generated.replaceAll("\n", "").replaceAll("  ", " ").trim();
	}

	public static final String generated(DelegateGenerator delegateGenerator) {
		return delegateGenerator.generate();
	}

	public static final DelegateGenerator java(final Node node) {
		return new DelegateGenerator() {
			public String generate() {
				JavaProducer visitor = new JavaProducer();
				node.accept(visitor);
				return visitor.toString();
			}
		};
	}

	public static final DelegateGenerator xml(final Node node) {
		return new DelegateGenerator() {
			public String generate() {
				JavaProducer visitor = new JavaProducer();
				node.accept(visitor);
				return visitor.toString();
			}
		};
	}
}
